package com.xms.sdk.data;

import com.xms.core.SpringContextHolder;
import com.xms.sdk.core.query.QueryBase;
import com.xms.sdk.core.query.QueryByAttribute;
import com.xms.sdk.core.query.QueryExpression;
import com.xms.sdk.query.IQueryResolver;
import com.xms.sdk.query.IQueryResolverFactory;
import com.xms.sdk.query.QueryByAttributeResolver;
import com.xms.sdk.query.QueryExpressionResolver;
import org.springframework.stereotype.Service;

/**
 * <p>
 * QueryResolverFactory
 * </p>
 *
 * @author migo
 * @since 2021/9/1
 */
@Service
public class QueryResolverFactory implements IQueryResolverFactory {
    /*private List<IQueryResolver> _queryResolvers;
    @Autowired
    public void QueryResolverFactory(List<IQueryResolver> queryResolvers) {
        _queryResolvers = queryResolvers;
    }*/

    @Override
    public IQueryResolver getResolver(QueryBase query) {
        IQueryResolver queryResolver = null;
        if (query instanceof QueryExpression)
        {
            queryResolver = SpringContextHolder.getBean(QueryExpressionResolver.class);
            //queryResolver = _queryResolvers.stream().filter(x->x.getClass().equals(QueryExpressionResolver.class)).findFirst().orElse(null);
        }
        else if (query instanceof QueryByAttribute)
        {
            queryResolver = SpringContextHolder.getBean(QueryByAttributeResolver.class);
            //queryResolver = _queryResolvers.stream().filter(x->x.getClass().equals(QueryByAttributeResolver.class)).findFirst().orElse(null);
        }
        /*if(queryResolver != null){
            return queryResolver.init(query);
        }*/
        return queryResolver;
    }
}
